package xuexi;

import lombok.Data;

interface IDrawing {            //定义绘图标准
    public void draw();
}
@Data                           //免写getter setter方法的注解
class Coordinate{               //坐标类
    private double x;
    private double y;
    public Coordinate(double x, double y) {
        this.x = x;
        this.y = y;
    }
}
class Triangle implements IDrawing{         //三角形类
    private Coordinate []x;                 //坐标
    private Coordinate []y;
    private Coordinate []z;

    public Triangle(Coordinate[] x, Coordinate[] y, Coordinate[] z) {
        this.x = x;
        this.y = y;
        this.z = z;
    }

    @Override
    public void draw() {
        System.out.println("第一条边开始坐标("+this.x[0].getX()+","+this.x[0].getY()+")，结束坐标（"+this.x[1].getX()+","+this.x[1].getY()+")");
        System.out.println("第二条边开始坐标("+this.y[0].getX()+","+this.y[0].getY()+")，结束坐标（"+this.y[1].getX()+","+this.y[1].getY()+")");
        System.out.println("第三条边开始坐标("+this.z[0].getX()+","+this.z[0].getY()+")，结束坐标（"+this.z[1].getX()+","+this.z[1].getY()+")");
    }
}

class RoundShape implements IDrawing{           //圆形类

    private Coordinate []o;
    private double radius;

    public RoundShape(Coordinate[] o, double radius) {
        this.o = o;
        this.radius = radius;
    }

    @Override
    public void draw() {
        System.out.println("以圆心为（"+this.o[0].getX()+","+this.o[0].getY()+"),半径为:"+this.radius+"画圆！");
    }
}
class DrawFactory{                  //工厂设计模式
    public static IDrawing getInstane(String classname,double ... args){
        if ("triangle".equalsIgnoreCase(classname)){
            return new Triangle(
                        new Coordinate[]{
                                    new Coordinate(args[0],args[1]),new Coordinate(args[2],args[3])},
                        new Coordinate[]{
                                    new Coordinate(args[4],args[5]),new Coordinate(args[6],args[7])},
                        new Coordinate[]{
                                    new Coordinate(args[8],args[9]),new Coordinate(args[10],args[11])});
        }else if ("roundshape".equalsIgnoreCase(classname)){
            return new RoundShape(new Coordinate[]{new Coordinate(args[0],args[1])},args[2]);
        }else {
            return null;
        }
    }
}
public class PaintTest {
    public static  void main(String[] args){
        IDrawing iDrawingtriangle=DrawFactory.getInstane("triangle",1,1,2,2,3,3,4,4,5,5,6,6);
        iDrawingtriangle.draw();
        IDrawing iDrawingroundshape=DrawFactory.getInstane("roundshape",8,5,6);
        iDrawingroundshape.draw();
    }
}
